#!/usr/bin/python
import os
import sys

def main(args):
    if len(args) < 2:
        print "No hosts specified, stopping."
        sys.exit(1)
        
    hosts = args[1:]
    
    if not os.system("./make") == 0:
        print "./make returned non-zero, stopping."
        sys.exit(1)
    
    if not os.access("./ebin/server.beam", os.R_OK):
        print "Can't see ./ebin/server.beam, are you in the right place?"
        sys.exit(1)
        
    os.system("tar -cz -f ./swiftp_proxy_dev.tgz --exclude='*.svn' --exclude='swiftp_proxy_dev.tgz' ./")
    if not os.access("./swiftp_proxy_dev.tgz", os.R_OK):
        print "tar file isn't where it should be, it probably failed to create."
        sys.exit(1)
    
    for host in hosts:
        #print "scp to host: " + host
        #os.system("scp ./swiftp_proxy_dev.tgz " + host + ":/home/david/autostart.tgz")
        #print "scp finished."
        print "rsync to host: " + host
        os.system("rsync -av ./swiftp_proxy_dev.tgz " + host + ":/home/david/autostart.tgz")
        print "rsync finished."
    
    print "Done."

if __name__ == "__main__":
    main(sys.argv)

